package com.zonski.jbots.game.entity;

import com.zonski.jbots.engine.*;
import com.zonski.jbots.engine.entity.Mind;
import com.zonski.jbots.game.JBotsConstants;

/**
 * Created by IntelliJ IDEA.
 * User: Chris Glover
 * Date: Oct 20, 2003
 * Time: 5:48:00 PM
 * To change this template use Options | File Templates.
 */
public class BabyBotMind extends SeekerBotMind
{
    public BabyBotMind()
    {
        this.createCharge = true;
    }

    public void update(Engine engine)
        throws Exception
    {
        UsableResource cometMaker = (UsableResource)this.getEntity().getResource(JBotsConstants.COMET);
        cometMaker.stopUsing();
        super.update(engine);
    }

    public int getDesirability(QuickVector vector, int distance, int direction)
    {
        int desirability;
        if(distance == 1)
        {
            if(direction == this.getEntity().direction)
            {
                desirability = 50;
            }else{
                desirability = 40 + this.random.nextInt()%12;
            }
        }else{
            desirability = 0;
        }

        if(vector != null)
        {
            for(int i=vector.size(); i > 0 ; )
            {
                i--;
                Entity entity = (Entity)vector.elementAt(i);
                if(entity.entityType.getId() == JBotsConstants.BOMB_ID)
                {
                    // run away
                    if(distance < 3)
                    {
                        desirability -= 25;
                    }
                }else if(entity.entityType.getId() == JBotsConstants.CHARGE_ID ||
                        (entity.entityType.getId() == JBotsConstants.RECHARGE_ID &&
                        entity.getMode() != Modes.DEAD)){
                    desirability += (this.getEntity().getMaxCharge() - this.getEntity().getCharge());
                }else if(entity.layerId != this.getEntity().layerId){
                    if(JBotsConstants.isBot(entity.entityType.getId()))
                    {
                        desirability -= 25;
                        // pop off a shot too
                        UsableResource cometMaker = (UsableResource)this.getEntity().getResource(JBotsConstants.COMET);
                        cometMaker.startUsing(direction);
                    }
                }
            }
        }

        return desirability;
    }

    public Mind copy()
    {
        return new BabyBotMind();
    }
}
